package com.uestc.soft.service;

import com.uestc.soft.mapper.PortMapper;
import com.uestc.soft.pojo.Port;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PortService {
    @Resource
    private PortMapper portMapper;

    public Port selectById(Integer id) {   // 业务逻辑层
        return portMapper.selectById(id);
    }

    public Map<String, Object> hy_selectByPage(int page, int limit,String portNumber,String portProtocol,String processName) {
        // page 页码   (page-1)*limit=起始下标index
        int index = (page - 1) * limit;   // 计算出起始下标
        List<Port> portList = portMapper.hy_selectByPage(index, limit,portNumber,portProtocol,processName);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", portMapper.hy_selectCount(portNumber,portProtocol,processName));
        map.put("data", portList);
        return map;
    }

    public Map<String, Object> hy_insert(Port port) {
        portMapper.hy_insert(port);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "新增用户成功");
        return map;
    }

    public Map<String, Object> hy_deleteById(Integer id) {
        portMapper.hy_deleteById(id);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "删除用户成功");
        return map;
    }

    public Map<String, Object> updatePort(
            Integer id,Integer portNumber,String portProtocol,String processName,Integer numberOfHostMachines) {
        portMapper.updatePort(id,portNumber,portProtocol,processName,numberOfHostMachines);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "更新用户成功");
        return map;
    }

}
